package com.zpark.humpro.filter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import java.io.IOException;

/**
 * 全局编码拦截器
 */
@WebFilter("/*")  //拦截所有乱码
public class CharacterFilter extends HttpFilter {

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        //处理请求参数乱码
        req.setCharacterEncoding("UTF-8");
        //处理响应参数乱码
        res.setContentType("text/html;charset=utf-8");
        //无条件放行
        chain.doFilter(req,res);


    }
}
